#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;

void PrintPending(const sigset_t& pending)
{
    for(int signo = 31; signo > 0; signo--)
    {
        if(sigismember(&pending, signo))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << endl;
}

void handler(int signo)
{
    cout << "get a signo : " << signo << endl;
    while(true)
    {
        sigset_t pending;
        sigpending(&pending);
        PrintPending(pending);
        sleep(1);
    }
}

int main()
{
    cout << "getpid : " << getpid() << endl;
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigaction(2, &act, &oact); //对2号信号进行自定义捕捉
    while(true) sleep(1);
    return 0;
}